Crate pertable

source ·
Expand description

Periodic table in Rust

Provides an Element enum which has a few utility functions that are useful for general cheminformatics programming. Elements can be created either from the atomic number or the atomic symbol using the TryFrom and FromStr respectively.

This library provides a few utility functions useful for cheminformatics:

  • atomic_number
  • atomic_symbol
  • atomic_weight (WIP!)
  • n_valence_electrons (for SMILES parsing/perception, not for general use)
  • valence (for SMILES parsing/perception, not for general use)

This library has its own Error enum with the following variants:

  • InvalidAtomicNumber
  • InvalidAtomicSymbol
  • InvalidIsotope
  • InvalidFormalCharge

Here’s some example code:

use pertable::Element;

let element = Element::C;
assert_eq!(element.atomic_number(), 6);
assert_eq!(element.atomic_symbol(), "C".to_owned());
assert_eq!(element.atomic_weight(None).unwrap(), 12.0106);
assert_eq!(element.n_valence_electrons(0).unwrap(), 4);
assert_eq!(element.valence(0).unwrap(), 4);

Enums

  • Element enum for the periodic table of elements.
  • Error enum for pertable.